/**
 * Created by qlm on 2016/3/2.
 */
angular.module("directiveApp", [])
	.directive("langPrism", function(){
		return {
			replace:true,
			transclude:true,
			template:"<pre ng-transclude=''></pre>",
			link : function(scope,elem){
				Prism.highlightElement(elem[0], true);
			}
		}
	})
	.directive("anchor", function($location, $anchorScroll){
		return function(scope,elem,attrs){
			elem.on("click", function(){
				$location.hash(attrs.anchor);
				$anchorScroll();
			});
		}
	})
	.directive("fixMenu", function(){
		return function(scope, elem){
			var ot = elem[0].getBoundingClientRect().top;
			var ul = $(elem[0]).find("ul");
			ul.css("height",$(window).height() - 220)
				.css("overflow", "auto");

			$(window).scroll(function(e){
				ot = elem[0].getBoundingClientRect().top;

				if(ot <= 0){
					ul.css("position","fixed").css("height" , $(window).height());
				}else{
					ul.css("position","static").css("height",$(window).height() - 220);
				}
			});
		};
	});